<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div class="test" id="test"></div>
    <script src="../plugins/jquery-3.2.1.min.js"></script>
    <script src="../plugins/jquery-3.2.1.js"></script>

    <script>
         $(document).ready(function () {
            init();
        });

        function init(){
            if (typeof (WebSocket) == "undefined") {
                console.log("您的浏览器不支持WebSocket");
            } else {
                console.log("您的浏览器支持WebSocket");
                socket = new WebSocket("ws://127.0.0.1:8099/ws/welcome");
                //打开事件  
                socket.onopen = function () {
                    console.log("Socket 已打开");
                    //socket.send("这是来自客户端的消息" + location.href + new Date());  
                };
                //获得消息事件  
                socket.onmessage = function (msg) {
                    console.log(msg);
                    console.log(1111);
                    var data = msg.data;
                    if (data == 200) {
                        alert("连接成功！");

                        window.location.href = "../index.html"
                    } else {
                        //如果过期了，关闭连接、重置连接、刷新二维码  
                        socket.close();
                        // initQrImg();
                    }
                    //发现消息进入 开始处理前端触发逻辑  
                };
                //关闭事件  
                socket.onclose = function () {
                    console.log("Socket已关闭");
                };
                //发生了错误事件  
                socket.onerror = function () {
                    alert("Socket发生了错误");
                    //此时可以尝试刷新页面  
                }
        }
    }
    </script>
    
</body>
</html>